//
//  ST_FaceTipsFullScreenController.swift
//  btvideo
//
//  Created by Jason on 2021/12/8.
//  Copyright © 2021 JarvanZhang. All rights reserved.
//

import UIKit
import PINRemoteImage
import SwiftyAttributes

class ST_FaceTipsFullScreenController: UIViewController {
    
    
    override init(nibName: String?, bundle: Bundle?){
        super.init(nibName: nibName, bundle: bundle)
        self.overCurrentContext = true
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        view.backgroundColor = .clear
        view.addSubview(root_view)
        root_view.snp.makeConstraints { make in
            make.left.right.equalToSuperview()
            
            if iPhoneXSeries{
                make.bottom.equalToSuperview().offset(20)
                make.top.equalToSuperview().offset(statusBarHeight+55-20)
            }else{
                make.height.equalTo(757)
                make.centerY.equalToSuperview()
            }
            
            
        }
        
        
        root_view.addSubview(close_btn)
        close_btn.snp.makeConstraints { make in
            make.width.height.equalTo(44)
            make.right.equalToSuperview().offset(-11)
            make.top.equalToSuperview().offset(54-11)
        }
        
        root_view.addSubview(cover_image_view)
        cover_image_view.snp.makeConstraints { make in
            make.left.right.equalToSuperview()
            make.height.equalTo(429/375*ScreenWidth)
            make.top.equalToSuperview().offset(27)
        }
        
        root_view.addSubview(str_image_view)
        str_image_view.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.width.equalTo(231)
            make.height.equalTo(132)
            make.top.equalTo(cover_image_view.snp.bottom).offset(20)
        }
        
        root_view.addSubview(confirm_btn)
        confirm_btn.snp.makeConstraints { make in
            make.width.equalTo(190)
            make.height.equalTo(42)
            make.centerX.equalToSuperview()
            make.top.equalTo(str_image_view.snp.bottom).offset(40)
        }
        
    }
    
//MARK: - Properties
    private lazy var root_view:UIView = {
       let control = UIView()
        control.cornerRadius = 20
        control.backgroundColor = .white
        
        if !iPhoneXSeries{
            control.transform = CGAffineTransform.init(scaleX: 0.8, y: 0.8)
        }
        
        return control
    }()
    
    fileprivate lazy var close_btn:UIButton = {
        
        let control = UIButton.init(type: UIButton.ButtonType.custom)
        
        control.setImage(ST_ImageUtils.imageName("ticket_close"), for: .normal)
        
        control.addTarget(self, action: #selector(close_handle), for: UIControl.Event.touchUpInside)
        
        return control
    }()
    
    fileprivate lazy var cover_image_view:UIImageView = {
        let v = UIImageView()
        v.contentMode = .scaleAspectFill
        v.clipsToBounds = true
        v.pin_setImage(from: "http://btstatic-cdn.jingniaoapps.com/cdgw6ek1638961537".url)
        //v.cornerRadius = 5
        return v
    }()
    
    fileprivate lazy var str_image_view:UIImageView = {
        let v = UIImageView()
        v.contentMode = .scaleAspectFill
        v.clipsToBounds = true
        v.pin_setImage(from: "http://btstatic-cdn.jingniaoapps.com/uoiu4921638961420".url)
        return v
    }()
    
    fileprivate lazy var confirm_btn:UIButton = {
        let btn = UIButton.init(type: UIButton.ButtonType.custom)
        btn.setAttributedTitle("立即认证".withAttributes([.font(.systemFont(ofSize: 16, weight: .medium)),.textColor(.white)]), for: .normal)
        btn.backgroundColor = UIColor.init(hex: 0xED6B69)
        btn.cornerRadius = 42/2.0
        //btn.semanticContentAttribute = .forceRightToLeft
        btn.addTarget(self, action: #selector(next_handle), for: UIControl.Event.touchUpInside)
        return btn
    }()

}

extension ST_FaceTipsFullScreenController{
    
    @objc private func close_handle(){
        
        goback_previous_controller()
        
    }
    
    @objc private func next_handle(){
        
        if FACE_AVATAE_STATE == 4{
            
            self.toast(text: "你的头像还在审核中")
            
            return
        }
        
        goback_previous_controller(animated: false) {
        
            if FACE_AVATAE_STATE == 2{
                
                let failure = ST_MatchFaceFailureController()
                
                failure.overCurrentContext = true
                
                GlobalPresent(toController: failure)
                
            }else if FACE_AVATAE_STATE != 3{
                
                DetectFaceHandle()
            }
        }
    }
    
    
    
}


